package me.zxk.qwert_poetry.dto;

import lombok.Data;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

import java.io.Serializable;
import java.util.List;

@Data
public class PageResult<T> implements Serializable {

    private int totalCount;

    private int pageSize;

    private int totalPage;

    private int currPage;

    private boolean isFirstPage;

    private boolean isLastPage;

    private List<T> list;

    public PageResult(Page<T> page) {
        this.list = page.getContent();
        this.totalCount = (int)page.getTotalElements();
        this.pageSize = page.getSize();
        this.currPage = page.getNumber();
        this.totalPage = page.getTotalPages();
        this.isFirstPage = page.isFirst();
        this.isLastPage = page.isLast();
    }
}
